import { GetService } from '@/core/service';

export default {
	state: {
		userInfo: {},
		permInfo: {},
		appUpdate: true,
		aiSearch: true,
		keyWord: null
	},
	mutations: {
		setUserInfo(state, value) {
			state.userInfo = value;
		},
		setPermInfo(state, value) {
			state.permInfo = value;
		},
		setAppShow(state, value) {
			state.appUpdate = value;
		},
		setKeyWord(state, value) {
			state.keyWord = value.keyWord;
		},
		setAiSearch(state, value) {
			state.aiSearch = value.aiSearch;
		}
	},
	actions: {
		// 获取用户信息
		async getUserInfo({ commit }, obj) {
			const service = await GetService({ store: {} });
			
			const userInfo = await service.common.user.userInfo({
				type: 1,
				versionCode: obj.versionCode
			});
			commit('setUserInfo', userInfo);
		},
		// 清除用户信息
		async clearUserInfo({ commit }) {
			commit('setUserInfo', {});
		},
		// 获取功能权限表
		async getPermInfo({ commit }, obj) {
			let params = {
				app: 'hf',
				version: obj.version,
				os: obj.os // 0：苹果平台 1安卓平台
			};

			const service = await GetService({ store: {} });
			const permInfo = await service.common.perm.list(params);
			// 开启功能权限
			// permInfo.common.forEach(item => {
			// 	if (item.name === 'isShelf') {
			// 		item.status = 1;
			// 	}
			// })
			commit('setPermInfo', permInfo);
		}
	}
};
